﻿namespace XWord.WPF.Behaviors
{
    using System.Windows;
    using System.Windows.Interactivity;

    public class LoadingBehavior : Behavior<UIElement>
    {
        #region Fields

        // Using a DependencyProperty as the backing store for DataSource.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty DataSourceProperty =
            DependencyProperty.Register("DataSource", typeof(object), typeof(LoadingBehavior),
            new UIPropertyMetadata(null, (obj, arg) =>
            {
                if (arg.NewValue != null)
                {
                    ((LoadingBehavior)obj).AssociatedObject.Visibility = Visibility.Collapsed;
                }
            }));

        #endregion Fields

        #region Properties

        public object DataSource
        {
            get { return (object)GetValue(DataSourceProperty); }
            set { SetValue(DataSourceProperty, value); }
        }

        #endregion Properties
    }

    public class ReloadTriggerAction : TargetedTriggerAction<UIElement>
    {
        protected override void Invoke(object parameter)
        {
            var element = AssociatedObject as UIElement;
            element.Visibility = Visibility.Visible;
        }
    }
}